$(function () {
    $("#jqGrid").jqGrid({
        url: baseURL + 'dangan/dadjgll/list',
        datatype: "json",
        colModel: [			
			{ label: 'nbxh', name: 'nbxh', index: 'NBXH', width: 50, key: true },
			{ label: '土地使用者', name: 'landuser', index: 'LANDUSER', width: 80 }, 			
			{ label: '证号', name: 'zh', index: 'ZH', width: 80 }, 			
			{ label: '批准文号', name: 'pzwh', index: 'PZWH', width: 80 }, 			
			{ label: '土地座落', name: 'position', index: 'POSITION', width: 80 }, 			
			{ label: '档案保管地，保管单位', name: 'szd', index: 'SZD', width: 80 }, 			
			{ label: '批准机关', name: 'pzjg', index: 'PZJG', width: 80 }, 			
			{ label: '土地用途', name: 'tdyt', index: 'TDYT', width: 80 }, 			
			{ label: '地号', name: 'dh', index: 'DH', width: 80 }, 			
			{ label: '权属性质', name: 'qsxz', index: 'QSXZ', width: 80 }, 			
			{ label: '图号', name: 'th', index: 'TH', width: 80 }, 			
			{ label: '地类', name: 'dl', index: 'DL', width: 80 }, 			
			{ label: '土地等级', name: 'tddj', index: 'TDDJ', width: 80 }, 			
			{ label: '发证日期', name: 'fzrq', index: 'FZRQ', width: 80 }, 			
			{ label: '件数', name: 'js', index: 'JS', width: 80 }, 			
			{ label: '页数', name: 'ys', index: 'YS', width: 80 }, 			
			{ label: '密级', name: 'mj', index: 'MJ', width: 80 }, 			
			{ label: '保管期限', name: 'bgqx', index: 'BGQX', width: 80 }, 			
			{ label: '全宗号', name: 'qzh', index: 'QZH', width: 80 }, 			
			{ label: '目录号', name: 'mlh', index: 'MLH', width: 80 },
			{ label: '分类号', name: 'flh', index: 'FLH', width: 80 }, 			
			{ label: '案卷号', name: 'ajh', index: 'AJH', width: 80 },
			{ label: '年度', name: 'nd', index: 'ND', width: 80 }, 			
			{ label: '创建时间', name: 'createdate', index: 'CREATEDATE', width: 80 }, 			
			{ label: '借出状态，1表示借出，0表示未借出', name: 'status', index: 'STATUS', width: 80 }, 			
			{ label: '查看次数', name: 'viewcount', index: 'VIEWCOUNT', width: 80 }, 			
			{ label: '分类号', name: '父级分类号', index: '父级分类号', width: 80 }, 			
			{ label: '面积', name: 'tdmj', index: 'TDMJ', width: 80 }			
        ],
		viewrecords: true,
        height: 385,
        rowNum: 10,
		rowList : [10,30,50],
        rownumbers: true, 
        rownumWidth: 25, 
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page", 
            rows:"limit", 
            order: "order"
        },
        gridComplete:function(){
        	//隐藏grid底部滚动条
        	$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" }); 
        }
    });
});

var vm = new Vue({
	el:'#rrapp',
	data:{
		showList: true,
		title: null,
		daDjgll: {}
	},
	methods: {
		query: function () {
			vm.reload();
		},
		add: function(){
			vm.showList = false;
			vm.title = "新增";
			vm.daDjgll = {};
		},
		update: function (event) {
			var nbxh = getSelectedRow();
			if(nbxh == null){
				return ;
			}
			vm.showList = false;
            vm.title = "修改";
            
            vm.getInfo(nbxh)
		},
		saveOrUpdate: function (event) {
		    $('#btnSaveOrUpdate').button('loading').delay(1000).queue(function() {
                var url = vm.daDjgll.nbxh == null ? "dangan/dadjgll/save" : "dangan/dadjgll/update";
                $.ajax({
                    type: "POST",
                    url: baseURL + url,
                    contentType: "application/json",
                    data: JSON.stringify(vm.daDjgll),
                    success: function(r){
                        if(r.code === 0){
                             layer.msg("操作成功", {icon: 1});
                             vm.reload();
                             $('#btnSaveOrUpdate').button('reset');
                             $('#btnSaveOrUpdate').dequeue();
                        }else{
                            layer.alert(r.msg);
                            $('#btnSaveOrUpdate').button('reset');
                            $('#btnSaveOrUpdate').dequeue();
                        }
                    }
                });
			});
		},
		del: function (event) {
			var nbxhs = getSelectedRows();
			if(nbxhs == null){
				return ;
			}
			var lock = false;
            layer.confirm('确定要删除选中的记录？', {
                btn: ['确定','取消'] //按钮
            }, function(){
               if(!lock) {
                    lock = true;
		            $.ajax({
                        type: "POST",
                        url: baseURL + "dangan/dadjgll/delete",
                        contentType: "application/json",
                        data: JSON.stringify(nbxhs),
                        success: function(r){
                            if(r.code == 0){
                                layer.msg("操作成功", {icon: 1});
                                $("#jqGrid").trigger("reloadGrid");
                            }else{
                                layer.alert(r.msg);
                            }
                        }
				    });
			    }
             }, function(){
             });
		},
		getInfo: function(nbxh){
			$.get(baseURL + "dangan/dadjgll/info/"+nbxh, function(r){
                vm.daDjgll = r.daDjgll;
            });
		},
		reload: function (event) {
			vm.showList = true;
			var page = $("#jqGrid").jqGrid('getGridParam','page');
			$("#jqGrid").jqGrid('setGridParam',{ 
                page:page
            }).trigger("reloadGrid");
		}
	}
});